public class T {
    public static void duplicateZeros(int[] arr) {
        int prev=0;

        while(prev+1<arr.length){
            if(arr[prev]==0) {
                for (int i = arr.length - 2; i >= prev + 1; i--) {
                    arr[i + 1] = arr[i];
                }
                arr[++prev] = 0;
            }
            prev++;
        }
    }

    public static void duplicateZeros1(int[] arr) {
        int prev=0;
        int cur=1;

        while(cur<arr.length){
            if(arr[prev]==0){
                for(int i=arr.length-2;i>=cur;i--){
                    arr[i+1]=arr[i];
                }
                arr[cur]=0;
                cur+=2;
                prev+=2;
            }else{
                cur++;
                prev++;
            }
        }
    }

    public static void main(String[] args) {
        int[] arr={1,0,2,3,0,4,5,0};
        duplicateZeros(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }
}
